<?php
namespace app\admin\controller;

use think\session;
use app\admin\api\ConferenceMenus;
use app\admin\controller\Permissions;


/**
 * 会议站--站点菜单管理
 */
class Confermenus extends  Permissions{

    /**
     * 获取站点菜单列表
     */
    public function menusList(){

        //换区网站token
        $token = getapptoken();

        $data = new ConferenceMenus();

        //接收数据
        if($this->request->isPost()){

            $post = $this->request->post();
            $res = $data->menusList($token,$post);

            $site = $res->items;

            if(empty($site)){
                $this->assign('intrs',-1);
            }else{
                $intrs = getstandardconent($site);
                return json($intrs);
            }
        }else{
            $page = 1;
            $res = $data->menusList($token,$page);
            $site = $res->items;

            if(empty($site)){
                $this->assign('intrs',-1);
            }else{

                //列表总数
                $total = $res->meta->total;
                $intrs = getstandardconent($site);

                $this->assign('intrs',$intrs);
                $this->assign('total',$total);
            }
            return view();
        }
    }

    /**
     * 创建站点菜单
     */
    public function menusCreate(){
        if($this->request->isPost()) {

            //接收站点数据
            $post = $this->request->post();
            $data['translations'] = $post;

            //换区网站token
            $token = getapptoken();

            $data2 = new ConferenceMenus();
            $result = $data2->menusCreate( $data,$token);

            if ($result == 555){
                $this->success("提交成功");

            }else{
                $this->error("$result");
            }
        } else{
            //获取站点语言
            $lang = getlang();

            $this->assign('lang',$lang);
            return view();
        }

    }


    /**
     * 获取站点菜单详情
     * @return [type] [description]
     */
    public function menusDetails($id){

        //换取网站token
        $token = getapptoken();

        $data = new ConferenceMenus();
        $res = $data->menusDetails($id,$token);

        //获取站点语言
        $lang = getlang();

        $this->assign('lang',$lang);
        $this->assign('intr',$res);
        //var_dump($res);
        return view();

    }


    /**
     * 更新站点菜单
     */
    public function menusUpdate(){
        if($this->request->isPost()) {

            $post = $this->request->post();

            //换区网站token
            $token = getapptoken();

            //接收数据
            $id = $post['zh-CN']['uid'];
            $data['translations']= $post;

            $data2 = new ConferenceMenus();
            $res = $data2->menusUpdate($id,$data,$token);

            if ($res == 555){
                $this->success("修改成功");

            }else{
                $this->error("$res");
            }

        }

    }

    /**
     * 删除站点菜单
     */
    public function menusDelete(){
        if ($this->request->isPost()) {

            //接收数据
            $post = $this->request->post();
            $id = $post['id'];

            //换区网站token
            $token = getapptoken();

            //请求接口
            $data = new ConferenceMenus();

            if(!empty($post['lang'])){
                $lang = $post['lang'];
                $res = $data->menusDeleteOne($id,$token,$lang);
            }else{
                $res = $data->menusDelete($id,$token);
            }

            if ($res == 555) {
                $this->success("删除成功");

            } else {
                $this->error("$res");
            }
        }
    }

}